<?php
/**
 * Created by PhpStorm.
 * User: daimingkang
 * Date: 2018/12/24
 * Time: 6:39 PM
 */

namespace App\Api\Controllers\Ccb;

use Rtgm\sm\RtSm4;
use Rtgm\sm\RtSm3;
class PayController extends BaseController
{
    public function refund ($info, $pubkey)
    {

        $this->get_key($info, $pubkey);
        die;

        $transData = [
            'amt' => $info['AMT'],
            'orderNo' => $info['ORDERID'],
            'numberId' => $info['REFUND_NO']
        ];
        $key = md5('737FED64FF7C4B2E884CADDB858E1254');
        $authCode = '1234567890';
        $timeStamp = time();

        //$sm2 = new RtSm2('base64');;
        $sm4 = new RtSm4();
        $sm3 = new RtSm3();
        $data = $sm4->encrypt($key, json_encode($transData));
        $sign = $sm3->digest($timeStamp.$data.$key);
        $params = [
            'txnCode' => 'RF001',
            'mchtNo' => '105584048160326',//$info['MERCHANTID'],
            'termNo' => '10091048',//$info['POSID'],
            'timeStamp' => $timeStamp,
            'data' => $data,
            'sign' => $sign,
        ];
        $ret = $this->allin_request('https://smartpos.ccb.com/mistest/misapi/', $params);
        var_dump($ret);
    }

    public function get_key ($info, $pubkey)
    {
        $data = [
            'txnCode' => 'AU011',
            'mchtNo' => '1050062533137880001',
            'termNo' => '10638779',
            'timeStamp' => $this->get_microtime(),
            'publicKey' => $pubkey,
            'authCode' => '645851150912'
        ];
        $ret = $this->allin_request('https://smartpos.ccb.com/mistest/misapi/', $data);

        var_dump($ret);
    }

    public function get_microtime ()
    {
        $microtime = microtime(true); // 返回当前 Unix 时间戳和微秒数
        return round($microtime * 1000); // 将微秒转换为毫秒
    }

}
